package com.sarnath.sardoop.modules.hadoop.web;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sarnath.sardoop.common.bean.Response;
import com.sarnath.sardoop.common.web.BaseController;
import com.sarnath.sardoop.modules.hadoop.entity.MrJobCreateEntity;
import com.sarnath.sardoop.modules.hadoop.service.MapRedJobService;

@Controller
@RequestMapping(value = "${adminPath}/hadoop/job")
public class MapRedJobController  extends BaseController{
	@Resource
	MapRedJobService mapRedJob;
	
	@RequestMapping(value="run")
	@ResponseBody
	public Response run(@ModelAttribute MrJobCreateEntity condition){
		Response res=new Response();
		try {
			res.put("jobId",mapRedJob.runJob(condition));
		} catch (Exception e) {
			res.setStatus(1);
			res.setMsg(e.toString());
			logger.info("",e);
		}
		return res;
	}
	
	@RequestMapping(value="findJob")
	@ResponseBody
	public Response findJob(@RequestParam String jobId){
		Response res=new Response();
		try {
			res.put("job",mapRedJob.getJob(jobId));
		} catch (Exception e) {
			res.setStatus(1);
			res.setMsg(e.toString());
			logger.info("",e);
		}
		return res;
	}
}
